package com.icss.th.question.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.icss.th.question.pojo.Question;
import com.icss.th.question.service.QuestionService;

/**
 * Servlet implementation class QuestionServlet
 */
@WebServlet("/question")
public class QuestionServlet extends HttpServlet 
{
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		String id = request.getParameter("id");
		String paperId = request.getParameter("paperId");
		String sort = request.getParameter("sort");
		String next = request.getParameter("next");
		
		Question question = null;
		try 
		{
			question = QuestionService.getBrotherQuestion(id, paperId, sort, "1".equals(next));
		} 
		catch (Exception e) 
		{
			throw new ServletException(e.getMessage(), e);
		}
		
		if (question == null)
		{ 
			request.getRequestDispatcher("/error.jsp").forward(request, response);
		}
		else
		{
			request.setAttribute("question", question);
			request.getRequestDispatcher("/detail.jsp").forward(request, response);
		}
	}
}
